<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <title>SIGIT</title>
    </h:head>
    <h:body onload="document.getElementById('form1:codigo').focus()">
        <ui:composition template="#{mudarTemplateBean.template}">
            <ui:define name="centro">
               
                <div id="divCentro">
                    <p:messages globalOnly="true" showDetail="true"/>
                    <p:panel header="#{mens.CADASTRO_DE_VENDAS}" visible="true" toggleable="true" styleClass="painelCentral" >
                        <h:form id="form1">
                            <h:panelGrid columns="3">
                                <h:outputText value="#{mens.CLIENTE}" styleClass="outputText"/>
                                <h:selectOneMenu id="cliente" value="#{manterVendaBean.cliente.codigo}">
                                    <f:selectItems value="#{manterVendaBean.listaClientes}" var="cliente" itemLabel="#{cliente.nome}" itemValue="#{cliente.codigo}"/>
                                </h:selectOneMenu>
                                <p:message for="cliente"/>


                                <h:outputText value="#{mens.PRODUTO}" styleClass="outputText"/>
                                <h:selectOneMenu id="produto" value="#{manterVendaBean.produto.id}">
                                    <f:selectItems value="#{manterVendaBean.listaProduto}" var="produto" itemLabel="#{produto.nome}" itemValue="#{produto.id}"/>
                                </h:selectOneMenu>
                                <p:message for="produto"/>

                                <h:outputText value="#{mens.QUANTIDADE}" styleClass="outputText"/>
                                <p:inputText id="quantidade" required="true" value="#{manterVendaBean.quantidade}" size="5" >
                                    <f:validateRegex pattern="[0-9]*" for="quantidade" />
                                </p:inputText>
                                <p:message for="quantidade"/>

                                <h:outputText value="#{mens.VALOR}" styleClass="outputText" rendered="#{manterVendaBean.finalizouAdicionar}"/>
                                <p:inputText id="vDinheiro" required="true" value="#{manterVendaBean.valorDinheiro}" size="30" rendered="#{manterVendaBean.finalizouAdicionar}">
                                    <f:validateRegex pattern="[0-9_._,]*"/>
                                    <f:validateLength  maximum="7" />
                                </p:inputText>
                                <p:message for="vDinheiro"/>

                                <h:outputText value="#{mens.VALORCHEQUE}" styleClass="outputText" rendered="#{manterVendaBean.finalizouAdicionar}"/>
                                <p:inputText id="vCheque" required="true" value="#{manterVendaBean.valorCheque}" size="30" rendered="#{manterVendaBean.finalizouAdicionar}" >
                                    <f:validateRegex pattern="[0-9_._,]*"/>
                                    <f:validateLength  maximum="7" />
                                </p:inputText>
                                <p:message for="vCheque"/>

                                <h:outputText value="#{mens.DATA}" styleClass="outputText" rendered="#{manterVendaBean.finalizouAdicionar}"/>
                                <p:calendar id="data" required="true" value="#{manterVendaBean.dataVenda}" size="30" navigator="true" rendered="#{manterVendaBean.finalizouAdicionar}"/>
                                <p:message for="data"/>

                            </h:panelGrid>


                            <h:panelGrid columns="3">
                                <p:commandButton ajax="false" value="#{mens.ADDITEMCOMPRA}" action="#{manterVendaBean.addItemVenda}"/>
                                <p:commandButton ajax="false" value="#{mens.TERMINARADD}" action="#{manterVendaBean.finalizarAdicionarItens}" disabled="#{!manterVendaBean.existeItemAdd or manterVendaBean.finalizouAdicionar}"/>

                                <p:commandButton ajax="false" value="#{mens.INSERIR}" action="#{manterVendaBean.create}"  disabled="#{!manterVendaBean.existeItemAdd or !manterVendaBean.finalizouAdicionar}" />

                            </h:panelGrid>

                        </h:form>

                        <h:form>

                            <h:panelGrid>
                                <p:panel header="#{mens.PESQUISAR_POR}">
                                    <h:selectOneMenu >
                                        <f:selectItem itemLabel=""/>
                                        <f:selectItem itemLabel="Cliente"/>
                                        <f:selectItem itemLabel="Codigo"/>
                                        <f:selectItem itemLabel="Data"/>

                                    </h:selectOneMenu>
                                    <p:inputText  style="margin-left: 5px"/>
                                    <p:commandButton ajax="false" value="#{mens.PESQUISAR}" image="url(../img/pesquisa2.png)" action="#{manterVendaBean.findVendaEntities}" />
                                </p:panel>
                            </h:panelGrid>
                        </h:form>
                    </p:panel>

                    <h:form>


                        <p:panel header="#{mens.PAINEL_DE_PESQUISA}" visible="true" toggleable="true" styleClass="painelCentral">

                            <p:dataTable paginator="true" rows="4" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" rowsPerPageTemplate="5" emptyMessage="#{mens.TABELA_VAZIA}" value="#{manterVendaBean.listaVendas}" var="vendas" rendered="#{manterVendaBean.exibeTabela}">
                                <p:column>

                                    <f:facet name="header">Codigo</f:facet>
                                    <h:outputText value="#{vendas.codigovenda}"/>

                                </p:column>

                                <!--p:column>
                                    <f:facet name="header">Valor Cheque</f:facet>
                                    <h:outputText value="#{vendas.valorCheque}"/>
                                </p:column-->
                                <p:column>
                                    <f:facet name="header">Valor em Dinheiro</f:facet>
                                    <h:outputText value="#{vendas.valorDinheiro}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">Valor Total</f:facet>
                                    <h:outputText value="#{vendas.valorDinheiro}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">Data da Compra</f:facet>
                                    <h:outputText value="#{vendas.dataVenda}"/>

                                </p:column>
                            </p:dataTable>
                        </p:panel>
                    </h:form>

                </div>
            </ui:define>
        </ui:composition>
    </h:body>
</html>